package com.qdlc.p2p.biz.executer.impl;

import java.util.Map;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.executer.BaseExecuter;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.dal.dto.AccountCash;
import com.qdlc.p2p.dal.dto.OperationLog;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 提现异步通知成功
 *
 * @author lx
 * @version 2.0
 * @since 2014年7月31日
 */
@Service
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CashNotifySuccessExecuter extends BaseExecuter {

    @Override
    public void handleAccountWithLog() {
		Global.setTransfer(LogTplNid.LOG_TPL_KEY, LogTplNid.CASH_SUCCESS);
		Global.setTransfer("web_url", WEB_URL);
		accountService.deductUseMoneyAndTotal(super.user.getUserId(), SystemConfigs.ADMIN_ID, super.money);
    }

    @Override
    public void addOperateLog() {
        if (operator != null) {
            Map<String, Object> transferMap = Global.getTransfer();
            AccountCash cash = (AccountCash) transferMap.get("cash");
            OperationLog log = new OperationLog(super.user, operator, LogTplNid.CASH_SUCCESS);
            log.setOperationResult("用户名为" + operator.getUserName() + "（" + Global.getIP() + "）的操作员对用户为"
                    + super.user.getUserName() + "的提现ID为" + cash.getId() + "）进行确认提现成功操作");
            operationLogDao.save(log);
        }
    }
}
